package zjump.simplelibrary.root;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;

public abstract class BaseActivity extends Activity {

	protected ProgressDialog progressDialog;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(getContentLayoutId());
		create(savedInstanceState);
	}

	protected abstract int getContentLayoutId();

	protected abstract void create(Bundle savedInstanceState);

	protected void jumpActivity(Class<?> targetActivity) {
		Intent intent = new Intent(this, targetActivity);
		startActivity(intent);
	}

	protected void jumpActivity(Class<?> targetActivity, Intent data) {
		if (data == null) {
			data = new Intent(this, targetActivity);
		}
		startActivity(data);
	}

	protected void jumpActivity(Class<?> targetActivity, Intent data, int requestCode) {
		if (data == null) {
			data = new Intent(this, targetActivity);
		}
		startActivityForResult(data, requestCode);
	}

	protected void showProgressDialog(String... text) {
		if (progressDialog == null) {
			progressDialog = new ProgressDialog(this);
		}
		if (text != null && text.length > 0) {
			progressDialog.setMessage(text[0]);
		}
		progressDialog.show();
	}

	protected void dismissDialog() {
		if (progressDialog != null) {
			progressDialog.dismiss();
		}
	}

}
